import datetime

import tushare as ts

from x01_stock.xx_util.DBUtil import SqlHelper

ts.set_token('2b5ccf8aa515d2c654cef2598e2f85ef8ff7b88fc5047a2c1ebc0296')

pro = ts.pro_api()

# 查询当前所有正常上市交易的股票列表

df1 = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,fullname,enname,cnspell,market,exchange,curr_type,list_status,list_date,delist_date,is_hs,act_name,act_ent_type')

sql = (f"INSERT INTO ts_stock_list (stat_date,ts_code,symbol,name,area,industry,fullname,enname,cnspell,market,exchange,curr_type,list_status,list_date,delist_date,is_hs,act_name,act_ent_type"
       f") VALUES ('{datetime.now().date()}',%s, %s, %s, %s,%s, %s,%s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s)")  # SQL插入语句

for row in df1.itertuples(index=False):  # 遍历DataFrame中的每一行
    print(row)
    SqlHelper.get_instance().execute_curd(sql, row)
    print("正在插入数据:", row)  # 输出正在插入的数据

